package studychinese.fragment;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.hschinese.pronunciation.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.sharesdk.onekeyshare.OnekeyShare;


/**
 * A simple {@link Fragment} subclass.
 */
public class StudyFragment extends BaseFragment implements View.OnClickListener{


    @Bind(R.id.btn_share)
    Button btnShare;

    public StudyFragment() {
        // Required empty public constructor
    }

    public static StudyFragment newInstance() {

        Bundle args = new Bundle();

        StudyFragment fragment = new StudyFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_study, container, false);
        ButterKnife.bind(this, inflate);
        btnShare.setOnClickListener(this);
        return inflate;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onClick(View view) {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，微信、QQ和QQ空间等平台使用
        oks.setTitle(getString(R.string.app_name));
        // titleUrl QQ和QQ空间跳转链接
        oks.setTitleUrl("http://www.chinlab.com/");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("我的报告，大家快看看吧");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
//        oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        oks.setImageData(bitmap);
//        oks.setImagePath(R.drawable.ic_launcher);
        // url在微信、微博，Facebook等平台中使用
        oks.setUrl("http://www.chinlab.com/");
        // comment是我对这条分享的评论，仅在人人网使用
//        oks.setComment("我是测试评论文本");
        // 启动分享GUI
        oks.show(getContext());
    }
}
